{template /common/header}
<link rel="stylesheet" type="text/css" href="{THEME_PATH}style/style.css" /> 
<script type="text/javascript" src="{THEME_PATH}js/goods_detail.js"></script>
<script src="{JS_PATH}common.js" type="text/javascript"></script>
<script type="text/javascript">
var goods = {
    "goods_id"      : "{$id}",
    "product_id"    : 0,
    "title"         :"{$title}",
    // 促销类型
    "prom_type"     :"{$prom_type}"
};
var theme_path = "{THEME_PATH}";
var referer = -1;
var obj_title='商品详情';
</script>
<div class="app_body">
  <div class="app_spxq">
    <ul>
      {if $list_img}
      {loop $list_img $img}
      <li> <img src="{$img}" /> </li>
      {/loop}
      
      {/if}
    </ul>
    <div class="app_spxqLeft"></div>
    <div class="app_spxqRight"></div>
  </div>
  <div class="app_spxqTitle">
    <h1>{$name}</h1>
    <p> <span>销售价：<font>{MONUNIT}{$cruuent_price}</font></span> <span>市场价：{MONUNIT}{$market_price}<</span> </p>
  </div>
  <div class="app_spxqfenlei">
    <ul id="goods_specs">
                <?php foreach(unserialize($rs['spec_array']) as $k=>$v):?>
                <li class="goods_specs_col"><?php echo $v['name']?>：<p><?php foreach(str2arr($v[ 'value']) as $kk=>$vv):?><a href="javascript:;" data-id="<?php echo $v['id']?>" data-name="<?php echo $v['name']?>" data-value="<?php echo $vv?>" ><?php echo $vv?></a><?php endforeach;?></p></li>
                <?php endforeach;?>
            </ul>
    <div class="div2"> 货号：<span id="data_products_sn">{if $products_sn}{$products_sn}{else}-{/if}</span> </div>
  </div>
  <div class="app_spxqContent">
    <h1>商品详情</h1>
    <div class="shop_detail"> {$descript} </div>
  </div>
</div>
<div class="app_spxqFooter">
  <ul>
    <li id="collect"> <a href="/">首页</a> </li>
    <li> <a href="{U('Goods/Cart/index')}">购物车</a> </li>
    <li> <a href="javacript:void(0);" id="btn_cart">加入购物车</a> </li>
  </ul>
</div>
<script type="text/javascript">
// 收藏
$("#collect a").click(function(){
    var collect_url = "",collect_params = {goods_id : "{$id}"};
    var domCollect = $(this);
    var hasCollect = domCollect.hasClass("hover");
    if(hasCollect) {
        collect_url = "{U('User/Collect/delone')}";
    } else {
        collect_url = "{U('User/Collect/add')}";
    }
    $.post(collect_url, collect_params, function(ret) {
        if(ret.status == 1) {
            if(hasCollect) {
                domCollect.removeClass("hover");
            } else {
                domCollect.addClass("hover");
            }
        } else {
            hd_alert(ret.info);
            return false;
        }
    }, "JSON");
})
var allow_buy = false, cart_nums = 0, goods_number = {intval($rs[goods_number])};
$(function(){
   
    goods_detail.init();
    $("#btn_cart").click(function() {
        goods_detail.cart_add();
    });
    if($("#goods_specs").length == 0) {
        if(goods_number < 1) {
            $("#btn_cart").text('商品库存缺货').removeClass('hover').addClass('disabled');
        } else {
            allow_buy = true;
        }
    } else {
        $("#btn_cart").text('请选择规格').removeClass('hover').addClass('disabled');
    }
    $("#goods_specs a").on("click",function() {
        /* 不能选择 */
        if($(this).hasClass('disabled')) {
            return;
        }
        $(this).siblings("a").removeClass("selected");
        if($(this).hasClass('selected')){
            $(this).removeClass('selected');
        }else{
            $(this).addClass('selected');
        }
        /* 开始更改状态 */
        var product_json = <?php echo json_encode($products_arr)?>;
        var symbol  = '<?php echo $cruuent_symbol?>';
        var specs_array = new Array();
        var regexp = '';
        $("#goods_specs li").each(function(i){
            var selected = $(this).find("a.selected");
            if(selected.length>0) specs_array[i] = selected.attr("data-id") + ':' + selected.attr("data-value");
            else specs_array[i] = "\\\d+:\.+";
        })
        $("#goods_specs li").each(function(k){
            var selected = $(this).find("a.selected");
            /* 遍历属性 */
            $(this).find("a").each(function(){
                $(this).removeClass('disabled');
                var flage = false;
                var temp = specs_array.slice();
                temp[k] = $(this).attr('data-id') + ':' + $(this).attr('data-value');
                for(gi in product_json){
                    var item = product_json[gi];
                    var item_text = JSON.stringify(item);
                    var reg = new RegExp(temp.join(";"));
                    flage = reg.test(item_text);
                    if(flage) break;
                }
                if(!flage) $(this).addClass("disabled");
            });
        })
        var specKey = '';
        $('.goods_specs_col').each(function() {
            spec_id = $(this).find('a.selected').attr('data-id');
            spec_name = $(this).find('a.selected').attr('data-name');
            spec_value = $(this).find('a.selected').attr('data-value');
            //选择值 加入数组
            if ($(this).find('a.selected').length === 0) {
                return false;
            } else {
                specKey += spec_id+':'+spec_value+';' ;
            }
        });
        goods.product_id = 0;
        $("#btn_cart").text('请选择规格').removeClass('hover').addClass('disabled');
        if($('.specCol').length == $('.specCol .goods-color-choose').length){
            if(product_json[specKey] != undefined){
                var item = product_json[specKey];
                //限时促销的不需要更改价格
                var prom_name = "{$promotion[$prom_type]['name']}";
                if (goods.prom_type != 'timed' || prom_name.length == 0) {
                    $('#data_shop_price').text(symbol + item.shop_price);
                }
                $('#data_goodsNumber').text(item.goods_number);
                $('input[name="data_specKey"]').val(specKey);
                goods.product_id = item.id;
                //根据库存显示操作
                if (item.goods_number > 0) {
                    $("#btn_cart").text('加入购物车').removeClass('disabled').addClass('hover');
                    allow_buy = true;
                } else {
                    $("#btn_cart").text('商品库存缺货').removeClass('hover').addClass('disabled');
                    allow_buy = false;
                }
            }
        }
    })
    $(".dldt2 dt strong, p.more").click(function() {
        if($(this).attr('data-load') == 'comment') {
            goods_detail.loadComment();
        } else if($(this).attr('data-load') == 'consult') {
            goods_detail.loadConsult();
        }
    });
})
$(function()
{
	var winWidth = $(window).width();
	var liSize = $(".app_spxq > ul > li").length;
	var liNum = 0;
	//var liRNum = liSize - 1;
	$(".app_spxq").css("width",winWidth);
	$(".app_spxq > ul > li").css("width",winWidth);
	$(".app_spxq > ul").css("width" , winWidth * liSize);
	$(".app_spxqLeft").click(function()
	{
		liNum++;
		if(liNum < liSize)
		{
			$(".app_spxq > ul").animate({marginLeft: -(liNum * winWidth)});
		}
		else{
			liNum = liSize - 1;
		}
	});
	$(".app_spxqRight").click(function()
	{
		if(liNum != 0)
		{
			liNum--;
			if(liNum != liSize - 1)
			{
				$(".app_spxq > ul").animate({marginLeft: -(liNum * winWidth)});
			}
			else{
				liNum = 0;
			}
		}
	});
});
</script>
</body></html>